﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using COM.OA.BLL;
using COM.OA.Entity;

public partial class index_top_password : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //取登陆人信息 
        COM.OA.Entity.users loginuser = Session["loginuser"] as COM.OA.Entity.users;
        //如果取不到跳转到登陆页
        if (loginuser == null)
        {
            this.Response.Write(string.Format(GetRedirect.ALLREDIRECT, "../login.aspx"));
        }
        int loginuid= loginuser.u_id;
        string oldpd = this.Request["oldpd"];
        if (oldpd != loginuser.u_password)
        {
            this.Response.Write(string.Format(GetRedirect.WINALERT, "原始密码错误"));
            this.Response.Write(string.Format(GetRedirect.REDIRECT, "updatepassword.aspx"));
        }
        else
        {
            string newpd = this.Request["newpd"];
            users uu = usersBLL.Select(loginuid);
            uu.u_password = newpd;
            int flag = usersBLL.Update(uu);
            if (flag != 0)
            {
                this.Response.Write(string.Format(GetRedirect.WINALERT, "密码修改成功"));
                this.Response.Write(string.Format(GetRedirect.REDIRECT, "../officetable.aspx"));
            }
            else
            {
                this.Response.Write(string.Format(GetRedirect.WINALERT, "密码修改失败"));
                this.Response.Write(string.Format(GetRedirect.REDIRECT, "../login.aspx"));
            }
        }
    }
}
